package com.example.wechat;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wechat.adapter.MeMenuAdapter;
import com.example.wechat.model.MeMenuItem;

import java.util.ArrayList;
import java.util.List;

public class MeFragment extends Fragment {
    private RecyclerView menuRecyclerView;
    private ImageView avatar;
    private TextView nickname;
    private TextView wechatId;
    private MeMenuAdapter menuAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        initViews(view);
        setupRecyclerView();
        loadUserInfo();
        return view;
    }

    private void initViews(View view) {
        avatar = view.findViewById(R.id.avatar);
        nickname = view.findViewById(R.id.nickname);
        wechatId = view.findViewById(R.id.wechat_id);
        menuRecyclerView = view.findViewById(R.id.menu_recycler_view);
        
        menuRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        List<MeMenuItem> menuItems = createMenuItems();
        menuAdapter = new MeMenuAdapter(menuItems);
        menuRecyclerView.setAdapter(menuAdapter);
    }

    private void setupRecyclerView() {
        List<MeMenuItem> menuItems = createMenuItems();
        menuAdapter.setMenuItems(menuItems);
    }

    private void loadUserInfo() {
        // TODO: 从服务器或本地加载用户信息
        nickname.setText("张三");
        wechatId.setText("微信号: wxid_123456");
    }

    private List<MeMenuItem> createMenuItems() {
        List<MeMenuItem> items = new ArrayList<>();
        items.add(new MeMenuItem(R.drawable.ic_wallet, "支付", "", 0));
        items.add(new MeMenuItem(R.drawable.ic_collect, "收藏", "", 0));
        items.add(new MeMenuItem(R.drawable.ic_album, "相册", "", 0));
        items.add(new MeMenuItem(R.drawable.ic_card, "卡包", "", 0));
        items.add(new MeMenuItem(R.drawable.ic_emoji, "表情", "", 0));
        items.add(new MeMenuItem(R.drawable.ic_settings, "设置", "", 0));
        return items;
    }
} 